import { defineConfig, searchForWorkspaceRoot } from "vite";
import vueI18n from '@intlify/vite-plugin-vue-i18n'
import vue from "@vitejs/plugin-vue";
import path = require("path");
import { resolve } from "path";
const pathResolve = (dir) => {
  return resolve(__dirname, ".", dir);
}

export default defineConfig({
  plugins: [
    vue(),
    vueI18n({
      include: path.resolve(__dirname, './src/locales/language/**')
    }),],
  resolve: {
    // 全局src 路径重新命名
    alias: {
      "@": pathResolve("src"),
    }
  },
  // 本地运行配置，及反向代理配置
  server: {
    fs: {
      strict: false,
      allow: [
        searchForWorkspaceRoot(process.cwd()),
        '/path/to/custom/allow'
      ]
    },
    cors: true, // 默认启用并允许任何源
    open: true, // 在服务器启动时自动在浏览器中打开应用程序
    //反向代理配置，注意rewrite写法
    // proxy: {
    //   '/api': {
    //     target: 'http://192.168.99.223:3000',   //代理接口
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, '')
    //   }
    // }
  },
  // alias: {
  // "@": path.resolve(__dirname, "src"),
  // "comps": path.resolve(__dirname, "src/components"),
  // "router": path.resolve(__dirname, "src/router"),
  // "store": path.resolve(__dirname, "src/store"),
  // "styles": path.resolve(__dirname, "src/styles"),
  // "plugins": path.resolve(__dirname, "src/plugins"),
  // "views": path.resolve(__dirname, "src/views"),
  // "layouts": path.resolve(__dirname, "src/layouts"),
  // },
});
